package carouselMap

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/carouselmap"
	"github.com/zeromicro/go-zero/core/logc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CarouselMapInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 详情
func NewCarouselMapInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CarouselMapInfoLogic {
	return &CarouselMapInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CarouselMapInfoLogic) CarouselMapInfo(req *types.CarouselMapInfoReq) (resp *types.CarouselMapListItemRes, err error) {
	u, err := l.svcCtx.SettingService.CarouselMap.CarouselMapInfo(l.ctx, &carouselmap.CarouselMapInfoReq{Id: req.Id, MerchantId: 1})

	if err != nil {
		logc.Error(l.ctx, "CarouselMapInfo err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	if u.Data.Id == 0 {
		return nil, code.NotData
	}

	resp = &types.CarouselMapListItemRes{
		MerchantId: u.Data.MerchantId,
		Id:         u.Data.Id,
		Pic:        u.Data.Pic,
		JumpUrl:    u.Data.JumpUrl,
		Sort:       u.Data.Sort,
		Status:     int64(u.Data.Status),
	}

	return resp, nil
}
